import Vue from 'vue'
import Router from 'vue-router'
import example from './example'

const layout = () => import('@/components/layout/layout'),
    viewError = () => import('../components/layout/view-error'),
    exampleLayout = () => import('@/components/layout/example-layout'),
    layoutShop = () => import('@/components/layout/layout-shop'),
    // index = () => import('@/page/index'),
    // res
    home = () => import('@/page/res/home'),
    resList = () => import('@/page/res/list'),
    resDetail = () => import('@/page/res/detail'),
    cart = () => import('@/page/res/cart'),
    submit = () => import('@/page/res/submit'),
    success = () => import('@/page/res/success'),
    dataSubmit = () => import('@/page/res/dataSubmit'),
    // manager
    selfBuilt = () => import('@/page/manager/self-built'),
    selfBuiltAdd = () => import('@/page/manager/self-built-add'),
    selfBuiltRevise = () => import('@/page/manager/self-built-revise'),
    ipAmendment = () => import('@/page/manager/ip-amendment'),
    ipModification = () => import('@/page/manager/ip-modification'),
    application = () => import('@/page/manager/application'),
    offApplication = () => import('@/page/manager/off-application'),
    requirementDetails = () => import('@/page/manager/requirement-details'),
    history = () => import('@/page/manager/history'),
    requirementModify = () => import('@/page/manager/requirement-modify'),
    authorization = () => import('@/page/manager/authorization'),
    authorizationResDetail = () => import('@/page/manager/authorization-res-detail'),
    dataManage = () => import('@/page/manager/data-manage'),
    newDataManage = () => import('@/page/manager/newDataManage'),
    DetailDataManage = () => import('@/page/manager/DetailDataManage'),
    reqDetail = () => import('@/page/manager/req-detail'),
    // inventory = () => import('@/page/manager/inventory'),
    inventoryEdit = () => import('@/page/manager/inventory-edit'),
    dataRequirement = () => import('@/page/manager/data-requirement'),
    dataReqAdd = () => import('@/page/manager/dataReq-add'),
    needReply = () => import('@/page/manager/need-reply'),
    // sp-manager
    spManagerApplication = () => import('@/page/sp-manager/application'),
    spManagerOffApplication = () => import('@/page/sp-manager/off-application'),
    spManagerApplicationDetail = () => import('@/page/sp-manager/application-detail'),
    spManagerResList = () => import('@/page/sp-manager/res-list'),
    spManagerResDetail = () => import('@/page/sp-manager/res-detail'),
    spManagerResAdd = () => import('@/page/sp-manager/res-add'),
    spManagerImplementOrder = () => import('@/page/sp-manager/implement-order'),
    spManagerImplementIPOrder = () => import('@/page/sp-manager/implement-ip-order'),
    spManagerImplementIPOrderDetail = () => import('@/page/sp-manager/implement-ip-detail'),
    spManagerOffImplementOrder = () => import('@/page/sp-manager/off-implement-order'),
    spAmendment = () => import('@/page/sp-manager/sp-amendment'),
    spIpModify = () => import('@/page/sp-manager/sp-ip-modify'),
    // 初始路由集
    constantRouterMap = [
        {
            path: '/401',
            name: '401',
            component: viewError
        },
        {
            path: '/',
            name: 'index',
            component: layout
        },
        {
            path: '/exchange',
            name: 'exchange',
            component: layout,
            children: [
                {
                    path: 'data-requirement',
                    name: 'dataRequirementAndPro',
                    component: dataRequirement,
                    meta: {
                        title: '数据需求与问题反馈'
                    },
                    children: [
                        {
                            path: 'add',
                            name: 'dataReqAdd',
                            component: dataReqAdd,
                            meta: {
                                title: '新增数据需求与问题反馈'
                            }
                        },
                        {
                            path: 'detail',
                            name: 'reqDetail',
                            component: reqDetail,
                            meta: {
                                title: '查看'
                            }
                        }
                    ]
                },
                {
                    path: 'need-reply',
                    name: 'needReply',
                    component: needReply,
                    meta: {
                        title: '需求回复'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'requirementDerail',
                            component: reqDetail,
                            meta: {
                                title: '查看'
                            }
                        }
                    ]
                }
            ]
        }
    ],
    layoutRouter = [
        {
            path: '/res',
            name: 'res',
            component: layoutShop,
            children: [
                {
                    path: 'home',
                    name: 'home',
                    component: home,
                    meta: {
                        title: '首页',
                        identify: 'home'
                    }
                },
                {
                    path: 'list',
                    name: 'resList',
                    component: resList,
                    meta: {
                        title: '资源目录',
                        identify: 'resApply',
                        keepAlive: false
                    }
                },
                {
                    path: 'detail/:id',
                    name: 'resDetail',
                    component: resDetail,
                    meta: {
                        title: '资源详情',
                        identify: 'resApply'
                    }
                },
                {
                    path: 'cart',
                    name: 'resCart',
                    component: cart,
                    meta: {
                        title: '资源申请栏',
                        identify: 'resApply'
                    }
                },
                {
                    path: 'submit',
                    name: 'submit',
                    component: submit,
                    meta: {
                        title: '资源申请栏提交',
                        identify: 'resApply'
                    }
                },
                {
                    path: 'dataSubmit',
                    name: dataSubmit,
                    component: dataSubmit,
                    meta: {
                        title: '数据资源申请栏提交',
                        identify: 'resApply'
                    }
                },
                {
                    path: 'success',
                    name: 'success',
                    component: success,
                    meta: {
                        title: '资源申请栏成功',
                        identify: 'resApply'
                    }
                }
            ]
        }
    ],
    managerRouter = [
        {
            path: '/manager',
            name: 'manager',
            component: layout,
            children: [
                {
                    path: 'selfBuilt',
                    name: 'selfBuilt',
                    component: selfBuilt,
                    meta: {
                        title: '我的自建系统'
                    },
                    children: [
                        {
                            path: 'add',
                            name: 'selfBuiltAdd',
                            component: selfBuiltAdd,
                            meta: {
                                title: '新增自建系统'
                            }
                        },
                        {
                            path: 'detail/:id',
                            name: 'selfBuiltRevise',
                            component: selfBuiltRevise,
                            meta: {
                                title: '修改自建系统'
                            }
                        }
                    ]
                },
                {
                    path: 'ipAmendment',
                    name: 'ipAmendment',
                    component: ipAmendment,
                    meta: {
                        title: 'IP修改申请单'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'ipModification',
                            component: ipModification,
                            meta: {
                                title: '申请详情'
                            }
                        }
                    ]
                },
                {
                    path: 'ip-amend',
                    name: 'iPAudit',
                    component: spAmendment,
                    meta: {
                        title: 'IP修改'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spIpModifyDet',
                            component: spIpModify,
                            meta: {
                                title: '申请详情'
                            }
                        }
                    ]
                },
                {
                    path: 'dataManage',
                    name: 'dataManage',
                    component: dataManage,
                    meta: {
                        title: '数据源管理'
                    },
                    children: [
                        {
                            path: 'add',
                            name: 'newDataManage',
                            component: newDataManage,
                            meta: {
                                title: '新建'
                            }
                        }, {
                            path: 'detail',
                            name: 'DetailDataManage',
                            component: DetailDataManage,
                            meta: {
                                title: '查看'
                            }
                        }
                    ]
                },
                {
                    path: 'application',
                    name: 'application',
                    component: application,
                    meta: {
                        title: '已归集需求申请'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'requirementDetails',
                            component: requirementDetails,
                            meta: {
                                title: '申请详情'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'requirementHistory',
                                    component: history,
                                    meta: {
                                        title: '历史版本'
                                    }
                                }
                            ]
                        },
                        {
                            path: 'edit',
                            name: 'requirementModify',
                            component: requirementModify,
                            meta: {
                                title: '修改需求单'
                            }
                        }
                    ]
                },
                {
                    path: 'off-application',
                    name: 'offApplication',
                    component: offApplication,
                    meta: {
                        title: '未归集需求申请列表'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'offRequirementDetails',
                            component: requirementDetails,
                            meta: {
                                title: '申请详情'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'offRequirementHistory',
                                    component: history,
                                    meta: {
                                        title: '历史版本'
                                    }
                                }
                            ]
                        },
                        {
                            path: 'edit',
                            name: 'offRequirementModify',
                            component: requirementModify,
                            meta: {
                                title: '修改需求单'
                            }
                        }
                    ]
                },
                {
                    path: 'authorization',
                    name: 'authorization',
                    component: authorization,
                    meta: {
                        title: '我的资源'
                    },
                    children: [
                        {
                            path: 'resDetail/:id',
                            name: 'authorizationResDetail',
                            component: authorizationResDetail,
                            meta: {
                                title: '资源详情'
                            }
                        }
                    ]
                },
                {
                    path: 'demand',
                    name: 'spApplication',
                    component: spManagerApplication,
                    meta: {
                        title: '已归集需求审核'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spManagerApplicationDetail',
                            component: spManagerApplicationDetail,
                            meta: {
                                title: '申请详情'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'spApplicationHistory',
                                    component: history,
                                    meta: {
                                        title: '历史版本'
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'off-demand',
                    name: 'spOffApplication',
                    component: spManagerOffApplication,
                    meta: {
                        title: '未归集需求审核'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spMangerOffApplicationDetail',
                            component: spManagerApplicationDetail,
                            meta: {
                                title: '申请详情'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'spOffApplicationHistory',
                                    component: history,
                                    meta: {
                                        title: '历史版本'
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'res-list',
                    name: 'spManagerResList',
                    component: spManagerResList,
                    meta: {
                        title: '资源管理'
                    },
                    children: [
                        {
                            path: 'detail/:id',
                            name: 'spResourceManagement',
                            component: spManagerResDetail,
                            meta: {
                                title: '资源详情'
                            }
                        },
                        {
                            path: 'inventory',
                            name: 'spManagerResourceInventory',
                            component: inventoryEdit,
                            meta: {
                                title: '编目编辑'
                            }
                        },
                        {
                            path: 'add',
                            name: 'spManagerResourceAdd',
                            component: spManagerResAdd,
                            meta: {
                                title: '新增资源'
                            }
                        }
                    ]
                }
            ]
        }
    ],
    spManagerRouter = [
        {
            path: '/sp-manager',
            name: 'sp-manager',
            component: layout,
            children: [
                {
                    path: 'res-list',
                    name: 'spManagerResourceList',
                    component: spManagerResList,
                    meta: {
                        title: '资源管理'
                    },
                    children: [
                        {
                            path: 'detail/:id',
                            name: 'spManagerResDetail',
                            component: spManagerResDetail,
                            meta: {
                                title: '资源详情'
                            }
                        },
                        {
                            path: 'inventory',
                            name: 'spManagerResInventory',
                            component: inventoryEdit,
                            meta: {
                                title: '编目编辑'
                            }
                        },
                        {
                            path: 'add',
                            name: 'spManagerResAdd',
                            component: spManagerResAdd,
                            meta: {
                                title: '新增资源'
                            }
                        }
                    ]
                },
                {
                    path: 'implement-order',
                    name: 'spManagerImplementOrder',
                    component: spManagerImplementOrder,
                    meta: {
                        title: '实施工单'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spManagerImplementOrderDetail',
                            component: spManagerApplicationDetail,
                            meta: {
                                title: '申请详情'
                            }
                        }
                    ]
                },
                {
                    path: 'implement-ip-order',
                    name: 'spManagerImplementIPOrder',
                    component: spManagerImplementIPOrder,
                    meta: {
                        title: 'IP实施工单'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spManagerImplementIPOrderDetail',
                            component: spManagerImplementIPOrderDetail,
                            meta: {
                                title: '申请详情'
                            }
                        }
                    ]
                },
                {
                    path: 'off-implement-order',
                    name: 'spManagerOffImplementOrder',
                    component: spManagerOffImplementOrder,
                    meta: {
                        title: '未归集实施工单'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spManagerOffImplementOrderDetail',
                            component: spManagerApplicationDetail,
                            meta: {
                                title: '申请详情'
                            }
                        }
                    ]
                },
                {
                    path: 'demand',
                    name: 'spMangerApplication',
                    component: spManagerApplication,
                    meta: {
                        title: '已归集需求审核'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spApplicationDetail',
                            component: spManagerApplicationDetail,
                            meta: {
                                title: '申请详情'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'spApplicationHistoryDet',
                                    component: history,
                                    meta: {
                                        title: '历史版本'
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'off-demand',
                    name: 'spMangerOffApplication',
                    component: spManagerOffApplication,
                    meta: {
                        title: '未归集需求审核'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spOffApplicationDetail',
                            component: spManagerApplicationDetail,
                            meta: {
                                title: '申请详情'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'spOffApplicationHistoryDet',
                                    component: history,
                                    meta: {
                                        title: '历史版本'
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'ip-amend',
                    name: 'spAmendment',
                    component: spAmendment,
                    meta: {
                        title: 'IP修改审批'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'spIpModify',
                            component: spIpModify,
                            meta: {
                                title: '申请详情'
                            }
                        }
                    ]
                }
            ]
        }
    ]

/*
* 开发环境添加example示例路由，可跳转查看组件如何使用
* 上线时将这一段注释
*/
if (process.env.NODE_ENV !== 'production') {
    constantRouterMap.push({
        path: '/example',
        name: 'example',
        component: exampleLayout,
        meta: {
            title: '控件示例'
        },
        children: []
    })
    constantRouterMap[constantRouterMap.length - 1].children.unshift(...example)
}

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // 页面跳转更改浏览器标题
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router

export {
    layoutRouter,
    managerRouter,
    spManagerRouter
}
